/**
 * 
 */
package supa;

import java.io.IOException;
import java.io.InputStream;
/* Copyright 2008 Rene Weiskircher 
 * 
 * This file is part of SUPA.

SUPA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SUPA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SUPA.  If not, see <http://www.gnu.org/licenses/>.
*/
import junit.framework.TestCase;

/**
 * @author Rene Weiskircher (rene.weiskircher@gmail.com)
 *
 */
public class SupaTest extends TestCase {

	/**
	 * Test method for {@link supa.Supa#Supa(java.lang.String[])}.
	 * @throws IOException 
	 * 
	 */
	public void testSupa() throws IOException {
		String[] t2 = {"povray","test","x"};
		String[] t3 = {"povray","test","0"};
		String[] t4 = {"povray","TestData/animation.ini","4711"};
		boolean caught = false;
		try {
			new Supa(t2);
		}
		catch(Supa.ArgumentException ex) {
			caught = true;
			assertEquals('T',ex.getMessage().charAt(0));
		}
		assertTrue(caught);
		caught = false;
		try {
			new Supa(t3);
		}
		catch(Supa.ArgumentException ex) {
			caught = true;
			assertEquals('C',ex.getMessage().charAt(0));
		}
		assertTrue(caught);
		try {
			Supa s = new Supa(t4);
			assertEquals(4711, s.procs.length);
			assertEquals("animation.ini", Supa.getIniFile().getName());
			assertEquals(0, s.startFrame);
			assertEquals(20,s.endFrame);
		}
		catch(Supa.ArgumentException ex) {
			fail();
		}
	}
	/**
	 * Check if we can actually start a simple process
	 */
	public void testProcess() {
		ProcessBuilder pb = new ProcessBuilder("ls");
		try {
			Process p  = pb.start();
			p.waitFor();
			InputStream in = p.getInputStream();
			int availableBytes = in.available();
			assertTrue(availableBytes > 0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
